function songTreeView()
{

    this.columns = ["siteId", "date", "duration"];
    this.orderColumn = this.columns[0];
    this.orderDirection = 1;
    this.searchText = "";
    this.searchColumn = "";

    this.recalculateRows = function () {
        this.cacheRowNum = -1;
        var whereclause = this.searchColumn ? "WHERE "+this.searchColumn+" LIKE (?1)" : "";
        var count;
        if (whereclause) 
            count = doSQL("SELECT COUNT(*) FROM Session "+whereclause, null, null, ["%"+this.searchText+"%"]);
        else 
            count = doSQL("SELECT COUNT(*) FROM Session");
        this.rowCount            = count[0][0];
        /*if(this.rowCount == 0) { 
            if (this.searchColumn == "siteId") {
                this.searchColumn = "first_line";
                this.recalculateRows();
                return;
            } else if (this.searchColumn == "first_line") {
                this.searchColumn = "xml";
                this.recalculateRows();
                return;
            } else {
                ff.setAttribute("status", "notfound");
            }
        } else {
            ff.removeAttribute("status");
        }*/
    }

    this.getCellText         = function(row,column){ 
        if (row > this.rowCount - 1) return;
        return (this.getSongAtIndex(row))[column.id]();
    };
    this.getSongAtIndex      = function(row) {
        var whereclause = this.searchColumn ? "WHERE "+this.searchColumn+" LIKE (?1)" : "";
        var orderclause = this.orderColumn + (this.orderDirection ? "": " DESC");
        if (row != this.cacheRowNum){
            var limitclause = "LIMIT 1 OFFSET "+row;
            var sql=  "SELECT * FROM Session "+whereclause+" ORDER BY "+orderclause+" "+limitclause
            var res;
            if (whereclause)
                res = doSQL(sql, Session, null, ["%"+this.searchText+"%"]);
            else 
                res = doSQL(sql, Session);
            this.cacheRow = res[0];
            this.cacheRowNum = row;
        }
        return this.cacheRow;
    };
    this.setTree             = function(treebox){ this.treebox=treebox; };
    this.isContainer         = function(row){ return false; };
    this.isSeparator         = function(row){ return false; };
    this.isSorted            = function(row){ return false; };
    this.getLevel            = function(row){ return 0; };
    this.getImageSrc         = function(row,col){ return null; };
    this.getRowProperties    = function(row,props){ };
    this.getCellProperties   = function(row,col,props){};
    this.getColumnProperties = function(colid,col,props){};
    this.cycleHeader = function (col) {
        if (col.id == this.orderColumn) {
            this.orderDirection = !this.orderDirection;
        } else {
            this.orderColumn = col.id;
        }
        this.treebox.invalidate();
        this.cacheRowNum = -1; // Invalidate cache
    }
    this.recalculateRows();
    return this;
}
